import React from "react";
import type { DataAction, IProTableRef } from "@yaf/pro-ui";
import { RespDataType, getMenuList } from "../../api";

export const getDataAction = (_: React.MutableRefObject<IProTableRef>, setIsShow: (val: boolean) => void): DataAction => ({
  fetchList: (params) => {
    const { filter } = params;
    return getMenuList({ "menuName": "", "component": "", ...filter }).then((resp) => {
      const loop = (rules: RespDataType.MenuItem[]): RespDataType.MenuItem[] => {
        return rules.map(item => {
          item.children = Array.isArray(item.children) && item.children.length > 0 ? loop(item.children) : null;
          setIsShow(true)
          return item;
        })
      }
      return loop(resp.data.rules)
    })
  },
})


